package com.cl.myInterface.impl;

import com.cl.annotation.ClComponent;
import com.cl.annotation.ClController;
import com.cl.container.MyContainer;
import com.cl.myInterface.DisposeClass;

import java.lang.annotation.Annotation;
import java.util.List;

/*
* 扫描所有的bean
* */
public class ScannerAllClBeanClass implements DisposeClass {
    @Override
    public int order() {
        return 1;
    }

    @Override
    public void dispose(List<Class> clazz) {
        clazz.forEach(clazs->{
            Annotation annotation = clazs.getAnnotation(ClComponent.class);
            if (annotation != null) {
                Class<? extends Annotation> aClass = annotation.annotationType();
                if (aClass == ClComponent.class) {
                    ClComponent component = (ClComponent) annotation;
                    //代表自定义组件
                    if (component != null) {
                        if (component.isBean()) {
                            //收集所有bean的Class
                            MyContainer.putInjectClass(component.value(), clazs);
                        }
                    }
                }
            }



            Annotation annotation2 = clazs.getAnnotation(ClController.class);
            if (annotation2 != null) {
                Class<? extends Annotation> aClass = annotation2.annotationType();
                if (aClass == ClController.class) {
                    ClController clController = (ClController) annotation2;
                    //代表自定义组件
                    if (clController != null && clController.isController()){
                        //收集所有controller的Class
                        MyContainer.putInjectClass(clController.value(), clazs);
                    }
                }
            }
        });
    }
}
